package edu.java.ishop.acessor;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;




import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


@Deprecated
public abstract class DatabaseDatasourceAccessor {

	private final InitialContext initCtx;
	
	public DatabaseDatasourceAccessor() {
		try {
			initCtx = new InitialContext();
		} catch (NamingException e) {
			// TODO log
			throw new RuntimeException(e);
		}
	}

	public Connection openAccess() throws SQLException{
		//datasource
		try {
			DataSource ds = (DataSource) initCtx.lookup("java:/comp/env/jdbc/postgres");
			return  ds.getConnection();
		} catch (NamingException | SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
		//jdbc
		//return DriverManager.getConnection(getconnectionUrl(), getUserName(), getPassword());
	}

	public abstract String getPassword(); 

	public abstract String getUserName(); 

	public abstract String getconnectionUrl(); 
}
